﻿Imports System
Imports System.Collections
Imports System.Globalization

Namespace System.Workflow.ComponentModel.Compiler
    <Serializable> _
    Public NotInheritable Class ValidationError
        ' Methods
        Public Sub New(ByVal errorText As String, ByVal errorNumber As Integer)
            Me.New(errorText, errorNumber, False, Nothing)
        End Sub

        Public Sub New(ByVal errorText As String, ByVal errorNumber As Integer, ByVal isWarning As Boolean)
            Me.New(errorText, errorNumber, isWarning, Nothing)
        End Sub

        Public Sub New(ByVal errorText As String, ByVal errorNumber As Integer, ByVal isWarning As Boolean, ByVal propertyName As String)
            Me.errorText = String.Empty
            Me.errorText = errorText
            Me.errorNumber = errorNumber
            Me.isWarning = isWarning
            Me.propertyName = propertyName
        End Sub

        Public Shared Function GetNotSetValidationError(ByVal propertyName As String) As ValidationError
            Return New ValidationError(SR.GetString("Error_PropertyNotSet", New Object() { propertyName }), &H116) { _
                .PropertyName = propertyName _
            }
        End Function

        Public Overrides Function ToString() As String
            Return String.Format(CultureInfo.InvariantCulture, "{0} {1}: {2}", New Object() { If(Me.isWarning, "warning", "error"), Me.errorNumber, Me.errorText })
        End Function


        ' Properties
        Public ReadOnly Property ErrorNumber As Integer
            Get
                Return Me.errorNumber
            End Get
        End Property

        Public ReadOnly Property ErrorText As String
            Get
                Return Me.errorText
            End Get
        End Property

        Public ReadOnly Property IsWarning As Boolean
            Get
                Return Me.isWarning
            End Get
        End Property

        Public Property PropertyName As String
            Get
                Return Me.propertyName
            End Get
            Set(ByVal value As String)
                Me.propertyName = value
            End Set
        End Property

        Public ReadOnly Property UserData As IDictionary
            Get
                If (Me.userData Is Nothing) Then
                    Me.userData = New Hashtable
                End If
                Return Me.userData
            End Get
        End Property


        ' Fields
        Private errorNumber As Integer
        Private errorText As String
        Private isWarning As Boolean
        Private propertyName As String
        Private userData As Hashtable
    End Class
End Namespace

